home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / misc / WindowsVersion.h < prev   
Text File  |  2011-11-06  |  4KB  |  135 lines

  1.  
  2. BOOL DisplaySystemVersion(LPTSTR buffer)
  3. {
  4.     OSVERSIONINFOEX osvi;
  5.     BOOL bOsVersionInfoEx;
  6.     
  7.     LPTSTR tmp=buffer;
  8.     
  9.     // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
  10.     // If that fails, try using the OSVERSIONINFO structure.
  11.     
  12.     ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
  13.     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  14.     
  15.     if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
  16.     {
  17.         // If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
  18.         osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  19.         if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
  20.             return FALSE;
  21.     }
  22.     
  23.     switch (osvi.dwPlatformId)
  24.     {
  25.         // Tests for Windows NT product family.
  26.     case VER_PLATFORM_WIN32_NT:
  27.         
  28.         // Test for the product.
  29.         
  30.         if ( osvi.dwMajorVersion <= 4 )
  31.             tmp+=_stprintf( tmp, _T("Microsoft Windows NT ") );
  32.         
  33.         if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
  34.             tmp+=_stprintf( tmp, _T("Microsoft Windows 2000 ") );
  35.         
  36.         
  37.         if( bOsVersionInfoEx )  // Use information from GetVersionEx.
  38.         { 
  39.             // Test for the workstation type.
  40.             if ( osvi.wProductType == VER_NT_WORKSTATION )
  41.             {
  42.                 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
  43.                     tmp+=_stprintf ( tmp, _T("Microsoft Windows XP ") );
  44.                 
  45.                 if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
  46.                     tmp+=_stprintf ( tmp, _T("Home Edition ") );
  47.                 else
  48.                     tmp+=_stprintf ( tmp, _T("Professional ") );
  49.             }
  50.             
  51.             // Test for the server type.
  52.             else if ( osvi.wProductType == VER_NT_SERVER )
  53.             {
  54.                 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
  55.                     tmp+=_stprintf ( tmp, _T("Microsoft Windows .NET ") );
  56.                 
  57.                 if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
  58.                     tmp+=_stprintf ( tmp, _T("DataCenter Server ") );
  59.                 else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
  60.                     if( osvi.dwMajorVersion == 4 )
  61.                         tmp+=_stprintf ( tmp, _T("Advanced Server ") );
  62.                     else
  63.                         tmp+=_stprintf ( tmp, _T("Enterprise Server ") );
  64.                 else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
  65.                     tmp+=_stprintf ( tmp, _T("Web Server ") );
  66.                 else
  67.                     tmp+=_stprintf ( tmp, _T("Server ") );
  68.             }
  69.         }
  70.         else   // Use the registry on early versions of Windows NT.
  71.         {
  72.             HKEY hKey;
  73.             TCHAR szProductType[80];
  74.             DWORD dwBufLen=80*sizeof(TCHAR);
  75.             
  76.             RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  77.                 _T("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
  78.                 0, KEY_QUERY_VALUE, &hKey );
  79.             RegQueryValueEx( hKey, _T("ProductType"), NULL, NULL,
  80.                 (LPBYTE) szProductType, &dwBufLen);
  81.             RegCloseKey( hKey );
  82.             if ( lstrcmpi( _T("WINNT"), szProductType) == 0 )
  83.                 tmp+=_stprintf( tmp, _T("Professional ") );
  84.             if ( lstrcmpi( _T("LANMANNT"), szProductType) == 0 )
  85.                 tmp+=_stprintf( tmp, _T("Server ") );
  86.             if ( lstrcmpi( _T("SERVERNT"), szProductType) == 0 )
  87.                 tmp+=_stprintf( tmp, _T("Advanced Server ") );
  88.         }
  89.         
  90.         // Display version, service pack (if any), and build number.
  91.         
  92.         if ( osvi.dwMajorVersion <= 4 )
  93.         {
  94.             tmp+=_stprintf ( tmp, _T("version %d.%d %s (Build %d)"),
  95.                 osvi.dwMajorVersion,
  96.                 osvi.dwMinorVersion,
  97.                 osvi.szCSDVersion,
  98.                 osvi.dwBuildNumber & 0xFFFF);
  99.         }
  100.         else
  101.         { 
  102.             tmp+=_stprintf ( tmp, _T("%s (Build %d)"),
  103.                 osvi.szCSDVersion,
  104.                 osvi.dwBuildNumber & 0xFFFF);
  105.         }
  106.         break;
  107.         
  108.         // Test for the Windows 95 product family.
  109.     case VER_PLATFORM_WIN32_WINDOWS:
  110.         
  111.         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
  112.         {
  113.             tmp+=_stprintf ( tmp, _T("Microsoft Windows 95 ") );
  114.             if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
  115.                 tmp+=_stprintf( tmp, _T("OSR2 ") );
  116.         } 
  117.         
  118.         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
  119.         {
  120.             tmp+=_stprintf ( tmp, _T("Microsoft Windows 98 ") );
  121.             if ( osvi.szCSDVersion[1] == 'A' )
  122.                 tmp+=_stprintf( tmp, _T("SE ") );
  123.         } 
  124.         
  125.         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
  126.         {
  127.             tmp+=_stprintf ( tmp, _T("Microsoft Windows Millennium Edition ") );
  128.         } 
  129.         break;
  130.     }
  131.     if (tmp==buffer)
  132.         tmp+=_stprintf( tmp, _T("%d.%d build %d"), osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber);
  133.     return TRUE; 
  134. }
  135.